import request from "@/utils/request";

export function serialNumber() {
  return request({
    url: "api/v1/common/serial_number",
    method: "get",
  });
}

/* 获取读卡器token */
export function getReadCardToken(code?: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "api/v1/manager/common/getReadCardToken";
      break;
    case "Corp":
      url = "api/v1/common/getReadCardToken";
      break;
    default:
      url = "api/v1/common/getReadCardToken";
  }
  if (code) {
    url = "api/v1/common/getReadCardToken";
  }
  return request({
    url: "api/v1/common/getReadCardToken",
    method: "get",
    params: {
      corpCode: code,
    },
  });
}

/*
 * 获取读卡器信息
 * */
export function getCardInfo(token: string) {
  return request({
    url: `api/v1/common/getCardInfo`,
    method: "get",
    params: {
      token,
    },
  });
}

/* 同意读卡器协议 */
export function confirmCardReader(code?: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "api/v1/manager/common/confirmCardReader";
      break;
    case "Corp":
      url = "api/v1/corp/common/confirmCardReader";
      break;
    default:
      url = "api/v1/common/confirmCardReader";
  }
  return request({
    url: url,
    method: "put",
    params: {
      corpCode: code,
    },
  });
}

/* 获取读卡器token */
export function getManagerReadCardToken() {
  return request({
    url: "api/v1/manager/common/getReadCardToken",
    method: "get",
  });
}

/* 同意读卡器协议 */
export function confirmManagerCardReader() {
  return request({
    url: "api/v1/manager/common/confirmCardReader",
    method: "put",
  });
}

/* 获取模板 */
export function GetTemplates(type: number) {
  return request({
    url: `api/v1/common/getTemplates/${type}`,
    method: "get",
  });
}
/* 下载模板 */
export function downloadTemplate(id: string) {
  return request({
    url: `api/v1/common/downloadTemplate/${id}`,
    method: "get",
    responseType: "arraybuffer",
  });
}

/* 下载附件 */
export function downloadAttachment(id: string) {
  return request({
    url: `api/v1/common/download/${id}`,
    method: "get",
    responseType: "arraybuffer",
  });
}

/*获取总包分包的下拉*/
export function GetCorpsManager(data: any) {
  return request({
    url: "api/v1/common/corps_manager",
    method: "get",
    params: data,
  });
}

export function ManagerExists(cardNo: string) {
  return request({
    url: "api/v1/account/manager_exists",
    method: "get",
    params: {
      cardNo: cardNo,
    },
  });
}

/* 密码强度验证 */
export function PassWordStrengthVerify(value: string) {
  return request({
    url: "api/v1/common/getPasswordStrength",
    method: "get",
    params: {
      passWord: value,
    },
  });
}

/*修改密码*/
export function UpdatePassWord(password: string) {
  let url = "";
  switch (localStorage.getItem("usertypeName")) {
    case "SysUser":
      url = "api/v1/sysuser/common/updatePassWord";
      break;
    case "Manager":
      url = "api/v1/manager/common/updatePassWord";
      break;
    default:
      url = "api/v1/manager/updatePassWord";
  }
  return request({
    url: url,
    method: "put",
    params: {
      password: password,
    },
  });
}
